// Queen.cpp
//
// Created By: Jeremy Butler
// Created On: 11-Apr-2011

#include "Queen.h"
#include "Board.h"
#include "Rook.h"
#include "Bishop.h"
#include "UnitTest.h"
#include "ChessController.h"
#include <sstream>
using namespace std;

Queen::Queen() : Piece(), rook(new Rook()), bishop(new Bishop()){
  return;
}

Queen::Queen(const Color _color) : Piece(_color, QUEEN),
				   rook(new Rook(_color)),
				   bishop(new Bishop(_color)){
  return;
}

Queen::Queen(const Queen & other) : Piece(other),
				    rook(other.rook->Clone()),
				    bishop(other.bishop->Clone()){
  return;
}

Queen * Queen::Clone() const{
  return new Queen(*this);
}

Queen::~Queen(){
  delete rook;
  delete bishop;
  return;
}

string Queen::ToString() const{
  stringstream str;

  string sColor;
  if(color == WHITE)
    sColor = "White";
  else if(color == BLACK)
    sColor = "Black";
  else
    sColor = "Colorless";

  str << sColor << " Queen";

  return str.str();
}

set<Location> Queen::GetValidMoves(const Board & board, int row, int col, bool AllMoves) const{
  set<Location> validRookMoves, validBishopMoves;
  Location location;
  
  validRookMoves = rook->GetValidMoves(board,row,col,AllMoves);
  validBishopMoves = bishop->GetValidMoves(board,row,col,AllMoves);

  for(set<Location>::iterator it = validBishopMoves.begin(); it != validBishopMoves.end(); it++)
    validRookMoves.insert(*it);

  if(!AllMoves)
    board.RemoveCheckMoves(validRookMoves,row,col);

  return validRookMoves;
}

bool Queen::Test(ostream & os){
  bool success = true;

  ChessView view;
  ChessController controller(view,0);

  controller.SetView(&view);
  view.SetController(&controller);

  controller.LoadGame("games/queenTest.xml");

  set<Location> moves;

  moves = controller.model->GetValidMoves(7,0);

  TEST(moves.size() == 17);

  moves = controller.model->GetValidMoves(6,4);

  TEST(moves.size() == 5);

  moves = controller.model->GetValidMoves(3,3);

  TEST(moves.size() == 27);

  return success;
}
